function  topicthumbsUp(topic_id,type){
//	if($('#'+topic_id+"_a").text().replace('点赞','')==0){
//	alert($('#'+topic_id+"_a").text().replace('点赞',''))
		 $.ajax({
				type : 'POST',
				dataType:'json', 
				url : ctp + '/interface/topicMarkOperate',
				data: {
					topic_id:topic_id,
					type:type//2-文章点赞 -3文章评论 4-转发 5-收藏 6-给评论点赞 7-给评论回复 8-不感兴趣
					//comment:comment,
					//topic_mark_id:topic_mark_id,
					//class_id:class_id
				},
				success:function(data){
					if(data.code==200){
						console.log(JSON.stringify(data.data));
						if(type==2){
							var mValue=parseInt($('#'+topic_id+"_a").text().replace('点赞',''))+1;
							$('#thumbs_cnt_1').text(mValue);
							$('#'+topic_id+"_a").text(mValue+'点赞');
							$('#'+topic_id+"_a").css("color","red");
							$('#zan_'+topic_id).unbind( "click");
							$('#zan_'+topic_id).bind("click",function(){
								topicthumbsUp(topic_id,10)
							});
							
							$("#aa_"+topic_id).removeClass("btn-white");
			 				$("#aa_"+topic_id).addClass("btn-danger");
							
						}else if(type==5){
							$('#collect_cnt_1').text(parseInt($('#collect_cnt_1').text())+1);
							$('#collect_cnt_word').text('取消收藏');
							$('#'+topic_id+"_b").unbind( "click");
							$('#is_collect_btn').removeClass("btn-white");
			 				$('#is_collect_btn').addClass("btn-danger");
			 				
							$('#'+topic_id+"_b").bind("click",function(){
								topicthumbsUp(topic_id,9)
							});
						}else if(type==9){
							$('#collect_cnt_1').text(parseInt($('#collect_cnt_1').text())-1);
							$('#collect_cnt_word').text('收藏');
							$('#'+topic_id+"_b").unbind( "click");
							
			 				$('#is_collect_btn').removeClass("btn-danger");
			 				$('#is_collect_btn').addClass("btn-white");
			 				
							$('#'+topic_id+"_b").bind("click",function(){
								topicthumbsUp(topic_id,5)
							});
						}else if(type==10){
							var mValue=parseInt($('#'+topic_id+"_a").text().replace('点赞',''))-1;
							$('#thumbs_cnt_1').text(mValue);
							$('#'+topic_id+"_a").text(mValue+'点赞');
							$('#zan_'+topic_id).unbind( "click");
							$('#zan_'+topic_id).bind("click",function(){
								topicthumbsUp(topic_id,2)
							});
							$('#'+topic_id+"_a").css("color","");
							$("#aa_"+topic_id).addClass("btn-white");
			 				$("#aa_"+topic_id).removeClass("btn-danger");
						}
			
					}
				},
				error:function(data){
				}
		    });
//	}

}

var Common={
		
}
//根据type 类型跳转不同的页面  0-普通话题 1-投票 2-问卷调查 3-活动管理,
Common.openDetailPage=function (topic_id,class_id,type ){
	if(type==0){
		location.href='web/topicDetail.jsp?topic_id='+topic_id+'&class_id='+class_id;
	}else if(type==1){
		location.href='web/voteDetail.jsp?topic_id='+topic_id+'&class_id='+class_id;
	}else if(type==2){
		location.href='web/surveyDetail.jsp?topic_id='+topic_id+'&class_id='+class_id;
	}else if(type==3){
		location.href='web/activityDetail.jsp?topic_id='+topic_id+'&class_id='+class_id;
	}
	 
}
//加入班组
Common.joinClass=function(){
	art.dialog({
		 left: '50%',
	     content: "申请理由:<input id='content' type='text'/>",
	     ok: function () {
	    	 if($('#content').val()==''){
	    		 art.dialog("申请理由不能为空", function(){});
	    	 }else{
	    		 $.ajax({
		    			type : 'POST',
		    			dataType:'json', 
		    			url : ctp + '/interface/classMemberAdd',
		    			data:{ 
		    				class_id:$('#class_id').val(),
		    				join_type:0,//0-主动加入班组 1-班组管理员拉人
		    				reason:$('#content').val()
		    				},
		    			success:function(data){
		    				if(data.code==200){
		    					$("#join_class").unbind("click",Common.joinClass);
		    					 art.dialog("操作成功，等待管理员审核", function(){});
		    				}else{
		    					 art.dialog(data.msg, function(){});
		    				}
		    			},
		    			error:function(data){
		    			}
		    	   });
	    	 }
	    },
	    cancelVal: '关闭',
	    cancel: true //为true等价于function(){}
	});
}
//退出班组
Common.quitClass=function(){
	art.dialog({
		 left: '50%',
	     content: "确认退出班组?",
	     ok: function () {
	    		 $.ajax({
		    			type : 'POST',
		    			dataType:'json', 
		    			url : ctp + '/interface/classMemberDelete',
		    			data:{ 
		    				class_id:$('#class_id').val(),
		    				type:0 //0主动退出班组 1 班组删人
		    				},
		    			success:function(data){
		    				if(data.code==200){
		    					$("#join_class").bind("click",Common.joinClass);
		    					$('#join_status').removeClass("fa-paper-plane");
		 						$('#join_status').addClass("fa-plus");
		    					 art.dialog("操作成功", function(){});
		    				}else{
		    					 art.dialog(data.msg, function(){});
		    				}
		    			},
		    			error:function(data){
		    			}
		    	   });
	    },
	    cancelVal: '关闭',
	    cancel: true //为true等价于function(){}
	});
}

Common.addTopic=function(){
	location.href=ctp+"/web/topicAdd.jsp"
}
//构建话题
Common.buildTopic=function(data){
	var result='';
	for(var i=0;i<data.data.length;i++){
		var cover_pic='';
		//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
		if(data.data[i].cover_pic ==''){
			if(data.data[i].pic_list==''){
				cover_pic="images/nopic.jpg";
			}else{
				cover_pic=data.data[i].pic_list[0];
			}
			
		}else{
			cover_pic=data.data[i].cover_pic;
		}				
		result+='<div class="ibox-content">';
		result+='<div class="row">';
		result+='<div class="col-md-3"> <img  class="img-responsive" src="'+cover_pic+'"></div>';
        result+='<div class="col-md-9">';
		result+='<div class="row">';
        result+='<div class="col-md-12 ">';
        result+='<div class="col-md-8"> ';
		result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
		result+='<h2>';		
        if(data.data[i].is_top==1){
        	result+='<button class="btn btn-danger" type="button">置顶</button>';        	        	
        }
        if (data.data[i].type==1){
    		result+='&nbsp;<button class="btn btn-danger" type="button">投票</button>&nbsp;';
    	}else if (data.data[i].type==2){
    		result+='&nbsp;<button class="btn btn-danger" type="button">问卷调查</button>&nbsp;';
    	}else if (data.data[i].type==3){
    		result+='&nbsp;<button class="btn btn-danger" type="button">活动报名</button>&nbsp;';
    	}
        result+=data.data[i].title+'</h2>';
   		result+='</a>';
   	    result+='</div>';
        result+='<div class=" col-md-4 ">';
        result+='<span class="pull-right"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
        result+='</div>';
        result+='</div>';
        result+='</div>';
        result+='<br>';
        result+='<div class="row">';
        result+='<div class="col-md-12" ><div class="col-md-12" ><p>'+data.data[i].indroduce+'</p></div></div>';
        result+='</div>';
        result+='<div class="row m-t-sm " >';
        result+='<div class="col-md-9">';
        result+='<div class="col-md-4 ">  ';
        result+='<img  id="pic" class="img-circle" src="'+data.data[i].class_pic+'"  style="width: 20px;height:20px">&nbsp;<button class="btn btn-success btn-xs"  type="button">'+data.data[i].class_name+'</button>';
        result+='</div>';
        result+='<div class="col-md-2 text-center"><a javascript:void(0)  class="btn-link">';
        result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
        if (data.data[i].type==0){
    		 result+=''+data.data[i].read_cnt+'人已阅读';
    	}else {
    		 result+=''+data.data[i].join_cnt+'人参与';
    	}
        result+='</button></a></div>';
        result+='<div class="col-md-2 text-center"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
        result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
        result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
        result+='</button></a></div>';
        result+='<div class="col-md-2 text-center "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
        result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button" > ';
        result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
        result+='</button></a></div>';
        result+='<div class="col-md-2 text-center " >'; 
        if(data.data[i].is_thumbs==0){//用户已经点赞
        	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white btn-xs" type="button"  onclick="topicthumbsUp('+data.data[i].topic_id+',10)"><i class="fa fa-thumbs-o-up" style="color:red"   id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
        }else{//用户还未点赞
        	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"  id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i> ';
        }
        result+='</button></div>';
        result+='</div>';
        result+='</div>';
        result+='</div>';
        result+='</div>';
        result+='</div>';
	}
	return result;
}
